package com.jp.knowledge.my.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.fragment.OrderFragment;
import com.jp.knowledge.view.TabView;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/5/4.
 */

public class OrderActivity extends SlidingActivity implements View.OnClickListener {

    @ViewInject(R.id.tab_view)
    private TabView tabView;
    @ViewInject(R.id.order_viewpager)
    private ViewPager viewPager;

    private List<Fragment> fragments;

    @Override
    protected int getResourceId() {
        return R.layout.activity_order;
    }

    @Override
    protected void init() {
        initTitleBar();
        fragments = new ArrayList<>();
        fragments.add(OrderFragment.newInstance(0));
        fragments.add(OrderFragment.newInstance(2));
        fragments.add(OrderFragment.newInstance(5));
        fragments.add(OrderFragment.newInstance(1));
        fragments.add(OrderFragment.newInstance(3));
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }
            @Override
            public int getCount() {
                return fragments.size();
            }
        });
        tabView.setTabItems("全部", "待完成", "已完成", "待付款", "已取消");
        tabView.setupWithViewPager(viewPager);
    }

    private void initTitleBar(){
        topName.setText("订单");
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightBtn.setText("我的发票");
        rightBtn.setVisibility(View.GONE);
        rightIcon.setVisibility(View.GONE);
        leftIcon.setOnClickListener(this);
        rightBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v == leftIcon){
            finish();
        } else if(v == rightBtn){

        }
    }
}
